package xj.graph2d.app.project;

import static xj.app.BaseApplicationFrame.getResourceString;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;

import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JTextField;

import xj.graph2d.app.DrawAction;
import xj.graph2d.dialog.DialogPanel;
import xj.graph2d.dialog.TitledDialogPanel;

public class ProjectCopyListener 
  extends DrawAction 
  implements ActionListener {

  class ProjectCopyOptionPanel extends DialogPanel {

    public ProjectCopyOptionPanel(String name) {
      super(name);
      JLabel currentNameLabel1 = new JLabel(getResourceString("CurrentProjectName.text") + " ");
      currentNameLabel = new JLabel(); 

      JLabel nameLabel = new JLabel(getResourceString("ProjectName.text") + " ");
      nameField = new JTextField();

      JLabel typeLabel = new JLabel(getResourceString("ProjectType.text") + " ");
      typeField = new JComboBox();
      typeField.addItem(ProjectType.UML);
      typeField.addItem(ProjectType.Default);
      typeField.setEnabled(false); 

      JLabel ctimeLabel1 = new JLabel(getResourceString("Create.text") + " ");
      ctimeLabel = new JLabel();

      addRow(currentNameLabel1, currentNameLabel);
      addRow(nameLabel, nameField);
      addRow(typeLabel, typeField);
      addRow(ctimeLabel1, ctimeLabel);

      setPreferredSize(new Dimension(400, 200));
      setOption();
    }

    @Override
    public void setOption() {
      ProjectManager projectManager = main.getProjectManager();
      Project project = projectManager.getCurrentProject();
      String name = project.getName();
      ProjectType type = project.getProjectType();
      currentNameLabel.setText(name); 
      String newname = projectManager.getNewProjectName(null); 
      nameField.setText(newname);
      typeField.setSelectedItem(type);
      ctimeLabel.setText((new Date()).toString());
    }

    @Override
    public void applyOption() {
      ProjectManager projectManager = main.getProjectManager();
      Project project = projectManager.getCurrentProject();
      String name = nameField.getText();
      if (!projectManager.hasProject(name)) {  
	
      }
    }

    protected JLabel currentNameLabel;

    protected JTextField nameField;

    protected JComboBox typeField;

    protected JLabel ctimeLabel;

  }

  protected TitledDialogPanel projectCopyOptionDialog = null;
  protected ProjectCopyOptionPanel projectCopyPanel = null;
  
  protected String projectCopyPanelTitle;
  protected String projectCopyDialogTitle;
  protected String projectCopyHeader;
  protected String[] projectCopyText;
  
  @Override
protected void init() { 
    projectCopyPanelTitle = getResourceString("ProjectCopy.title");
    projectCopyDialogTitle = getResourceString("ProjectCopyDialog.title");
    projectCopyHeader = getResourceString("ProjectCopyDialog.header");
    projectCopyText = new String[] { 
	getResourceString("ProjectCopyDialog.text1"),
	getResourceString("ProjectCopyDialog.text2"),	
    };
  }
  
  public void actionPerformed(ActionEvent e) {
    if (projectCopyOptionDialog == null) {
      DialogPanel[] options = { 
	projectCopyPanel = new ProjectCopyOptionPanel(projectCopyPanelTitle), 
      };
      projectCopyOptionDialog = new TitledDialogPanel(main.getJFrame(), 
						      JOptionPane.OK_CANCEL_OPTION, 
						      null, options);
      projectCopyOptionDialog.setTitle(projectCopyDialogTitle);
      projectCopyOptionDialog.setTitlePaneText(projectCopyHeader, projectCopyText);
    }
    projectCopyOptionDialog.setOptions();
    projectCopyOptionDialog.showOptionDialog();
  }

}
